extends KinematicBody2D
class_name Player

export (int) var PlayerSpeed

var velocity = Vector2.ZERO

var screensize
var at6 = true

# Called when the node enters the scene tree for the first time.
func _ready():
	screensize = get_viewport().size

	# signals
	CommonSignals.connect("PlayerNearElevator",self,"_on_NearElevator")
	CommonSignals.connect("PlayerLeaveElevator",self,"_on_LeaveElevator")
	CommonSignals.connect("PlayerNearDoor",self,"_on_NearDoor")
	CommonSignals.connect("PlayerLeaveDoor",self,"_on_LeaveDoor")
	CommonSignals.connect("Hide",self,"_on_Hide")
	CommonSignals.connect("UnHide",self,"_on_UnHide")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if velocity.length()>0:
		velocity = velocity.normalized() * PlayerSpeed
	
	position += velocity * delta
	position.x = clamp(position.x,0,screensize.x)
	position.y = clamp(position.y,0,screensize.y)
	
	
	

# when player reach the elevator
# press F enter the elevator, switch floor
func _on_NearElevator():
	pass
#	$Label.visible = true
	
func _on_LeaveElevator():
	pass
#	$Label.visible = false

# when player near the door
# press F open the door
func _on_NearDoor():
	pass
#	$Label.visible = true
	
func _on_LeaveDoor():
	pass
#	$Label.visible = false

func _on_Hide():
	print("hide")
	self.collision_layer = 2
	#这里应该玩家状态切换到另一个状态去

func _on_UnHide():
	print("unhide")
	self.collision_layer = 1
